package com.mrx.pvzcommunity.model.user;

import com.mrx.pvzcommunity.util.MD5Util;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel(value = "最少信息的 用户对象")
public class AvatarUser implements Serializable {

    @ApiModelProperty(value = "用户 头像 URL")
    private String avatar;
    @ApiModelProperty(value = "用户 昵称", example = "nickName")
    private final String uname;

    public AvatarUser(NormalUser normalUser) {
        setAvatar(normalUser.getMail());
        this.uname = normalUser.getUname();
    }

    public AvatarUser(User user) {
        setAvatar(user.getMail());
        this.uname = user.getUname();
    }

    public void setAvatar(String mail) {
        this.avatar = "https://gravatar.loli.net/avatar/" + MD5Util.md5Hex(mail);
    }
}
